package com.ysd.lis.service.qi.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.qi.QiIndexMajor;
import com.ysd.lis.mapper.qi.QiIndexMajorMapper;
import com.ysd.lis.service.qi.QiIndexMajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 质量指标专业 服务实现类
 * </p>
 *
 * @author LiuQi
 * @since 2024-02-03
 */
@Service
public class QiIndexMajorServiceImpl extends ServiceImpl<QiIndexMajorMapper, QiIndexMajor> implements QiIndexMajorService {

    @Autowired
    QiIndexMajorMapper qiIndexMajorMapper;

    @Override
    public Result getIndexMajorList(String indexCode) {
        LambdaQueryWrapper<QiIndexMajor> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(QiIndexMajor::getDelFlag, 0)
                .eq(QiIndexMajor::getIndexCode, indexCode)
                .orderByAsc(QiIndexMajor::getSeq);
        List<QiIndexMajor> qiIndexMajors = qiIndexMajorMapper.selectList(lambdaQueryWrapper);
        return Result.succ(1, "查询成功", qiIndexMajors);
    }

    @Override
    public Result addQiIndexMajor(QiIndexMajor qiIndexMajor) {
        boolean save = this.save(qiIndexMajor);
        if (save) {
            return Result.succ(1, "添加成功", null);
        } else {
            return Result.fail("添加失败");
        }
    }

    @Override
    public Result addQiIndexMajorList(List<QiIndexMajor> qiIndexMajor) {

        boolean b = this.saveBatch(qiIndexMajor);
        if(b){
            return Result.succ(1, "添加成功", null);
        }else {
            return Result.fail(400,"添加失败","");
        }
    }

    @Override
    public Result updateQiIndexMajor(QiIndexMajor qiIndexMajor) {
        boolean save = this.updateById(qiIndexMajor);
        if (save) {
            return Result.succ(1, "编辑成功", null);
        } else {
            return Result.fail("编辑失败");
        }
    }

    @Override
    public Result deleteQiIndexMajor(QiIndexMajor qiIndexMajor) {
        boolean delete = this.removeById(qiIndexMajor.getId());
        if (delete) {
            return Result.succ(1, "删除成功", null);
        } else {
            return Result.fail("删除失败");
        }
    }

}
